package com.cqcetbbs.smartlab.cqcetbbs.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cqcetbbs.smartlab.cqcetbbs.R;
import com.cqcetbbs.smartlab.cqcetbbs.javabean.ModuleInfo;

import java.util.ArrayList;

/**
 * Created by user on 2017/9/28.
 */

// 完成gridview 数据到界面的适配
public class GridViewAdapter extends BaseAdapter {

    ArrayList<ModuleInfo> lists;
    private Context context;

    public GridViewAdapter(Context context, ArrayList<ModuleInfo> lists) {
        this.context = context;
        this.lists = lists;
    }

    // 返回gridview里面有多少个条目
    public int getCount() {
        return lists.size();
    }

    //返回某个position对应的条目
    public ModuleInfo getItem(int position) {
        return lists.get(position);
    }

    //返回某个position对应的id
    public long getItemId(int position) {
        return position;
    }

    //返回某个位置对应的视图
    public View getView(int position, View convertView, ViewGroup parent) {
        //把一个布局文件转换成视图
        View view = View.inflate(context, R.layout.gridview_item, null);
        ImageView iv = (ImageView) view.findViewById(R.id.img_icon);
        TextView tv = (TextView) view.findViewById(R.id.tv_desc);
        //设置每一个item的名字和图标
        iv.setImageResource(lists.get(position).draw);
        tv.setText(lists.get(position).desc);
        return view;
    }

    private class ModuleInfoList {
    }
}